package com.atguigu.service.impl;

import com.atguigu.mapper.UserMapper;
import com.atguigu.pojo.User;
import com.atguigu.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @program:weiblog-server
 * @author: 马雨清
 * @Time: 2023/8/21  14:26
 * @description:
 */
@Service
@Transactional
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    @Transactional(readOnly = true)
    public User login(User user) {
        User selectUser = userMapper.loginUser(user.getUsername());
        if (null != selectUser){
            if (user.getPassword().equals(selectUser.getPassword())){
                return selectUser;
            }else {
                return null;
            }
        }
        return null;
    }

    @Override
    public User findById(Integer id) {
        User user = userMapper.selectById(id);
        if (null!=user){
            return user;
        }
        return null;
    }

    @Override
    public Integer modifyUser(User user) {
        Integer result = userMapper.updateUser(user);
        return result;
    }
}
